﻿<?php
//header("Content-type: text/html;charset=gbk");//输出编码,避免中文乱码
require_once (dirname(__FILE__) . "/../include/common.inc.php");
if(isset($_POST["page"])){
    @$page = max(1, intval($_POST["page"]));
   // 级别、区域、品牌、价格 价格
    // alert('s4pp===' +s4pp+ 's4jg==' +s4jg+ 'level=='+level+ 'area=='+area );
	$likeSql1 = "";
	$likeSql2 = "";
	$likeSql3 = "";
	$likeSql4 = "";
	
	if(isset($_POST["level"]) && !""==$_POST["level"] ) {
	        $likeSql1 .=" AND  t2.level = '".$_POST["level"]."' ";
	}
	
	if(isset($_POST["area"]) && !""==$_POST["area"] ) {
			$likeSql2 .=" AND t2.area = '".$_POST["area"]."' ";
	}
	
	if(isset($_POST["s4pp"]) && !""==$_POST["s4pp"] ) {
			$likeSql3 .=" AND t2.s4pp = '".$_POST["s4pp"]."' ";
	}
	
	if(isset($_POST["s4jg"]) && !""==$_POST["s4jg"] ) {
			$likeSql4 .=" AND t2.s4jg = '".$_POST["s4jg"]."' ";
	}
	
	// 基本条件 
	$mysql  = "SELECT t1.id,t1.title,t3.ename as area,t2.shopName,t2.address,t2.saleshotline ,t2.mouthword FROM dede_archives t1 ";
	$mysql .= "LEFT JOIN dede_addon4sks t2 ON t1.id = t2.aid left join dede_sys_enum t3 on t2.area = t3.disorder ";
	$mysql .= "  WHERE t3.egroup='area' and t2.typeid='12'  ";

	 $con = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
	 mysql_select_db($cfg_dbname, $con);
	 mysql_query("SET NAMES ".$cfg_db_language); 
												
	// 全部条件
	$querySql1 = $mysql.$likeSql1.$likeSql2.$likeSql3.$likeSql4;
	$n=mysql_num_rows($querySql1);

	if($n < $page) {
	    $querySql1 = $mysql.$likeSql2.$likeSql3.$likeSql4;
	    $n=mysql_num_rows($querySql1);
	} 
	if($n < $page) {
	    $querySql1 = $mysql.$likeSql3.$likeSql4;
	    $n=mysql_num_rows($querySql1);
	} 
	if($n < $page) {
	    $querySql1 = $mysql.$likeSql4;
	    $n=mysql_num_rows($querySql1);
	} 
	if($n < $page) {
	    $querySql1 = $mysql;
	} 
	
	//echo $likeSql;
	$mysql = $querySql1;
	$mysql .= " order by t2.sftjjxs asc limit  0,".$page ."  ";
	
    //echo $mysql;
    $query = mysql_query($mysql); 
    $divStr = '<table width="100%" border="0" cellspacing="0" cellpadding="0">					  <tr>
						<th colspan="4" style="align:center;color:red">我们还为你推荐以下经销商!</th>
					  </tr>';
					  
	    $odd = 1; // 奇偶行显示不同的眼神 
		while($row = mysql_fetch_array($query,MYSQL_ASSOC)) {
		     $odd ++;
			 $articles[] = array('id'=>$row['id'],'title'=>$row['title']);
			 if($odd%2 == 0) {
			    $divStr.= '<tr class="gray">';
			 } else {
				$divStr.= '<tr >';
			 }
			 $divStr.=' <td><a href="./view.php?aid='.$row["id"].'" target="_blank"><strong>'.$row["shopName"].'</strong></a></td>
						<td>'.$row["address"].'</td>
						<td>'.$row["saleshotline"].'</td>
						<td class="t_cen">'.$row["mouthword"].'</td>
				   </tr>';
		}
		$divStr.= '  </table>';
		echo $divStr;
	
	mysql_close($con);
    
}else{
    die();
}

/*
					      {dede:list pagesize='15'}
                          [field:global name='autoindex' runphp='yes']
                          	if(@me%2 == 0){
                          	 	@me = '<tr>';
                          	} else {
                          		@me = '<tr class="gray">';
                          	}
                          [/field:global]
                          <td><a href="[field:arcurl/]"><strong>[field:shopname/]</strong></a></td>
							 <td>[field:address/]</td>
							 <td>[field:saleshotline/]</td>
							 <td class="t_cen">[field:mouthword/]</td>
						   </tr>
			            {/dede:list}*/
?>

